<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">

<head>
    <th:block th:include="common/common_head :: commonHeader('发票')"/>
    <link rel="stylesheet" th:href="@{/static/js/plugins/jquery-layout/jquery.layout-latest.css}">
    <link rel="stylesheet" th:href="@{static/js/editable/css/bootstrap-editable.css}">
	<!-- <style type="text/css">.table {table-layout:fixed;}</style> -->
</head>

<body class="gray-bg">

<div class="container-div ui-layout-center">
    <div class="row">
		<div class="col-sm-12 search-condition">
			<form id="invoiceForm" th:action="@{/invoice/list}" class="form-inline">
				<div class="select-list">
				<ul>
					<li class="col-sm-3">
					<label style="width: 120px">采购凭证号：</label>
					<input type="text" name="poNo" />
					</li>
					<li class="col-sm-3">
					<label style="width: 120px">订单类型：</label>
					    <select name="poType" sysDict="CGDDLX" emptyFirst="true"></select>
					</li>
					<li class="col-sm-3">
					<label style="width: 120px">供应商SAP编码：</label>
					    <input type="text" name="sapCode"/>
					</li>
					<li class="col-sm-3">
					<label style="width: 120px">供应商SRM编码：</label>
					    <input type="text" name="srmCode"/>
					</li>
					<li class="col-sm-3">
					<label style="width: 120px">采购组：</label>
					    <select name="purchGroup" sysDict="CGZ" emptyFirst="true"></select>
					</li>
					<li class="col-sm-3">
					<label style="width: 120px">物料编码：</label>
					    <input type="text" name="materialCode" />
					</li>
					<li class="col-sm-3">
					<button id="invoiceSearchBtn" type="button" class="btn btn-primary btn-rounded btn-sm"><i class="fa fa-search"></i>&nbsp;搜索</button>
					<button class="btn btn-warning btn-rounded btn-sm" type="reset"><i class="fa fa-eraser"></i>&nbsp;重置</button>
					<button id="invoiceAdvancedSearch" type="button" class="btn btn-primary btn-rounded btn-sm" style="display: none"><i class="fa fa-caret-down"></i>&nbsp;高级搜索</button>
					</li>
				</ul>
				</div>
			</form>
		</div>
		
		<div class="col-sm-12 select-info order-table">
            <div class="btn-group hidden-xs toolbar" id="invoiceToolBar" role="group">
                <a class="btn btn-outline btn-success btn-rounded" onclick="agreeInvoices(true)">
                    <i class="fa fa-check"></i> 同意
                </a>
                <a class="btn btn-outline btn-success btn-rounded" onclick="agreeInvoices(false)">
                    <i class="fa fa-times"></i> 驳回
                </a>
            </div>
			<table id="invoice" data-mobile-responsive="true"></table>
		</div>
		
    </div>
</div>

<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<script type="text/javascript" th:src="@{/static/js/plugins/jquery-layout/jquery.layout-latest.js}"></script>

<script type="text/javascript">
    //面向对象
    var searcherBS = Searcher.createBS('#invoice',
        [
		{checkbox: true},
		{title: '发票类型', field:'invoiceType'},
		{title: '公司代码', field:'compCode'},
		{title: '供应商发票号', field:'invoiceNo'},
		{title: '会计输入凭证', field:'kjsrPz'},
		{title: '输入时间', field:'kjsrTime'},
		{title: '发票方', field:'invoicePerson'},
		{title: '采购订单号', field:'poNo'},
		{title: '会计凭证编号', field:'kjpzbh'},
		{title: '发票日期', field:'dateFp'},
		{title: '过账日期', field:'dateGz'},
		{title: '基准日期', field:'dateJz'},
		{title: '采购组', field:'purchGroup'},
		{title: '付款条件', field:'paymentTerm'},
		{title: '发票总额', field:'sumMoney'},
		{title: '凭证抬头文本', field:'bkTxt'},
		{title: '税码', field:'taxCode'},
		{title: '计算税额', field:'taxMoney'},
		{title: '税率', field:'taxRate'},
		{title: '货币码', field:'currency'},
		{title: '处理状态', field:'dealStatus', formatter : function (value, row, index) {
			if(value == 1) {return "未审核";}
			else if(value==2) {return "已同意";}
			else if(value==--2) {return "已驳回";}
			else {return "未审批";}
		}},
		{title: '备注', field:'remark'}
        ]
    );
    
    /**
     * 查询数据
     */
    function refresh() {
    	searcherBS.refresh();
    }
    
    $(function () {
    	initDictDataSel();//初始化所有字典数据
    });
    
    //操作发票（同意或者驳回）
    function agreeInvoices(agree) {
        var rowDatas = searcherBS.getSelectedRows("pkId");
        if (rowDatas.length <= 0) {
            Dialog.errorMsg("请至少选择一行进行操作！");
            return;
        }
	    Page.ajaxPOST(ctxPath +"/invoice/checkInvoices", {"pkIds":rowDatas, "agree":agree}, function(o) {
	        if(o.code == 0) {
	        	Dialog.msg("成功审核" + o.result + "份对账单");
	        } else {
	        	Dialog.alert("审核对账单失败!" + o.msg);
	        }
	        refresh();
		}, {"loadingMsg" : "正在往服务器提交数据……"});
    }
</script>
</body>
</html>